<template>
  <div class="fdsEarlywarningRuleset-remove-component">
    <el-dialog
      v-if="modelValue.visible"
      v-model="modelValue.visible"
      :title="`删除${modelValue.title}`"
      width="400px"
    >
      <span>确定要删除当前{{ modelValue.title }}记录？</span>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="cancel">取消</el-button>
          <el-button type="danger" @click="ensure"> 确定 </el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>
<script  setup lang='ts'>
//提示弹框。
import { ElMessage } from "element-plus";
//请求对应的删除接口。
import { batchRemoveFdsEarlywarningRuleset } from "@/api/fds-earlywarning-ruleset.api";
//获取从父组件传来的数据。
const props = defineProps(["modelValue"]);

const ensure = () => {
  let id = props.modelValue.curSelectRow.id;
  batchRemoveFdsEarlywarningRuleset([id])
    .then((res) => {
      cancel();
      ElMessage({
        message: props.modelValue.title + `记录删除成功`,
        type: "success",
      });

      if (props.modelValue.refreshDataList) {
        props.modelValue.refreshDataList();
      }
    })
    .catch((err) => {
      cancel();
      ElMessage({
        message: err.msg || err,
        type: "error",
      });
    });
};

const cancel = () => {
  props.modelValue.visible = false;
};
</script>
<style lang='scss' scoped>
</style>
